import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI, {Message} from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import axios from "axios";
import VideoPlayer from 'vue-video-player'
import 'vue-video-player/src/custom-theme.css'
import 'video.js/dist/video-js.css'
import VueAxios from "vue-axios"
import 'default-passive-events'

Vue.use(VueAxios, axios)

Vue.use(VideoPlayer)
Vue.use(ElementUI);
Vue.config.productionTip = false
Vue.prototype.$axios = axios
// 防止弹框导致页面抖动
ElementUI.Dialog.props.lockScroll.default = false;
ElementUI.Dialog.props.lockScroll.default = false;


//axios请求拦截器
axios.interceptors.request.use(
    config => {
        let token = localStorage.getItem('token');
        let userId =localStorage.getItem('userId')
        if (token) {
            config.headers['token'] = token;//请求头携带令牌token
            config.headers['userId']= userId;
        }
        return config;
    },
    error => {
        return Promise.reject(error);
    });

//axios响应拦截器
axios.interceptors.response.use(
    response => {
        if (response.data.msg === '未登录') {
            router.push('/homeView');
            return response;
        }else if(response.data.code===4000){
            localStorage.clear();
            setTimeout(() => router.push('/homeView'), 3000)
            return response;
        }
        else if(response.data.code===5010){
            localStorage.clear();
            Message.error("没有访问权限,请重新登录")
            setTimeout(() => router.push('/homeView'), 3000)
            router.go(0)
        }
        else {
            return response;
        }
    },
    error => {
        return Promise.reject(error);//将异常传递给下一个处理
    });

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
